package com.lifa.controller;

import com.lifa.dao.RuKuDao;
import com.lifa.entity.Kucun;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Controller
@RequestMapping("/RuKuTongJi")
@Scope("prototype")
public class RuKuContorller {
    @Autowired
    private RuKuDao ruKuTongJiDao;

    @RequestMapping("/queryRuKu")
    @ResponseBody
    public List<Kucun> queryRuKu(HttpServletRequest request){
       List<Kucun>list=ruKuTongJiDao.getAllRuKu();
       request.getSession().getServletContext().setAttribute("count",ruKuTongJiDao.getAllRuKuSL());
       request.getSession().getServletContext().setAttribute("price",ruKuTongJiDao.getAllRuKuPrice());
       return list;
    }
    public List<Kucun> queryRuKuSL(){
        return ruKuTongJiDao.getAllRuKuSL();
    }


    public List<Kucun> queryRuKuPrice(){
        return ruKuTongJiDao.getAllRuKuPrice();
    }

    @RequestMapping("/queryByName")
    @ResponseBody
    public Map<String,Object> queryPageByName(@RequestParam(value="id", defaultValue="0")int id, int offset, int limit){
        Map<String,Object> map = new HashMap<String, Object>();
        map.put("rows",ruKuTongJiDao.query(id,offset,limit));
        map.put("total",ruKuTongJiDao.getTotalCount(id));
        return map;
}



    @RequestMapping("/queryByRuKuMX")
    @ResponseBody
    public Map<String,Object> queryRuKuMX(@RequestParam(value = "id" , defaultValue = "0") int id,int offset,int limit){
        Map<String,Object> map=new HashMap<String,Object>();
        map.put("rows",ruKuTongJiDao.queryRuKuMX(id,offset,limit));
        map.put("total",ruKuTongJiDao.getTotalCountRuKuMX(id));
        return map;
    }



    @RequestMapping("/mx")
    @ResponseBody
    public List<Kucun> querymx(){
        List<Kucun> list=ruKuTongJiDao.getAllRuKujmx();
        return list;
    }




}
